package me.zhengjie.utils;

/**
 * Double工具类
 */
public class DoubleUtil {

    public static Double valueOf(String text) {
        return valueOf(text, null);
    }

    public static Double valueOf(String text, Double defaultValue) {
        if (StringUtil.isNullOrEmpty(text)) {
            return defaultValue;
        }

        try {
			return Double.parseDouble(text);
		} catch (NumberFormatException e) {
			return defaultValue;
		}
    }
    
    public static String displayFloat(Double value) {
    	if (value == null) {
			return "";
		}
    	String text = String.valueOf(value);
    	if (text.endsWith(".0")) {
			return text.substring(0, text.length() - 2);
		}
    	return text;
    }
}
